package com.xyhuo.leetcode.january;

import com.xyhuo.leetcode.common.TreeNode;

/**
 * 二叉树的最大深度
 * https://leetcode.cn/problems/maximum-depth-of-binary-tree/
 *
 * @time 2024/1/8
 */
public class MaxDepth {

    public int maxDepth(TreeNode root) {
        search(root, 0);
        return ans;
    }

    private int ans = 0;

    private void search(TreeNode root, int step) {
        if (root == null) {
            return;
        }
        if (step + 1 > ans) {
            ans = step + 1;
        }
        search(root.left, step + 1);
        search(root.right, step + 1);
    }
}
